package com.erp.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.erp.common.R;
import com.erp.entity.FinancialJournal;
import com.erp.service.FinancialJournalService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/journal")
@RequiresRoles(value = {"FinancialAdministrator","SupperAdministrator"},logical = Logical.OR)
public class FinancialJournalController {

    @Autowired
    private FinancialJournalService financialJournalService;

    @GetMapping("/page")
    public R<Page<FinancialJournal>> page(int page,int pageSize,String name){
        Page<FinancialJournal> journalPage = new Page<>(page,pageSize);
        LambdaQueryWrapper<FinancialJournal> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.orderByDesc(FinancialJournal::getTime);
        if (name!=null){
            lambdaQueryWrapper.like(FinancialJournal::getDetails,name);
        }
        financialJournalService.page(journalPage,lambdaQueryWrapper);
        return R.success(journalPage);
    }

    @DeleteMapping
    public R<String> deleteById(@RequestParam Long id){
        financialJournalService.removeById(id);
        return R.success("删除成功");
    }
}
